//
//  RefreshErrorAlertView.m
//  BDD_TWO
//
//  Created by WangZhenyu on 2019/12/20.
//  Copyright © 2019 WangZhenyu. All rights reserved.
//

#import "RefreshErrorAlertView.h"

@interface RefreshErrorAlertView()

@property (weak, nonatomic) IBOutlet UIImageView *contentImageView;
@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
@property (weak, nonatomic) IBOutlet UIButton *refreshBtn;
@property (weak, nonatomic) IBOutlet UILabel *desLabel;

@end

@implementation RefreshErrorAlertView

- (id)initItem:(CGRect)frame withType:(LoadErrorType)type withTip:(NSString *)tipStr{
    self = [[[NSBundle mainBundle] loadNibNamed:@"RefreshErrorAlertView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:frame];
        self.tipLabel.text = tipStr;
        [self setContentType:type];
    }
    return self;
}

- (id)initItem:(CGRect)frame withType:(LoadErrorType)type withTip:(NSString *)tipStr withButtonTitle:(NSString *)buttonTitle refresh:(void (^)(RefreshErrorAlertView *))refresh{
    self = [[[NSBundle mainBundle] loadNibNamed:@"RefreshErrorAlertView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:frame];
        self.tipLabel.text = tipStr;
        self.refreshBtn.hidden = NO;
        [self.refreshBtn setTitle:buttonTitle forState:UIControlStateNormal];
        [self.refreshBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        [self setContentType:type];
        self.RefreshHandle = refresh;
    }
    return self;
}

- (void)setContentType:(LoadErrorType)type {
     if (type == LoadErrorTypeNoNetwork) {
         self.contentImageView.image = [UIImage imageNamed:@"error_network"];
     } else if (type == LoadErrorTypeNoLogin) {
         self.contentImageView.image = [UIImage imageNamed:@"error_login"];
     } else if (type == LoadErrorTypeNoImage) {
         self.contentImageView.image = nil;
     }
     else{
         self.contentImageView.image = [UIImage imageNamed:@"error_nodata"];
     }
}

- (IBAction)refreshPress {
    if (self.RefreshHandle) {
        self.RefreshHandle(self);
    }
}
@end
